package swu.cx.finalproject

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_left_contact.*

class LeftContact: AppCompatActivity(){
    val contacts= arrayOf(
        contacts("陈子翀",R.mipmap.run2,"在么帅哥?"),
        contacts("刘金豪",R.mipmap.run3,"吃饭约么?"),
        contacts("小王",R.mipmap.run4,"我有bug待解决"),
        contacts("小红",R.mipmap.run5,"忙碌中,勿扰！"),
        contacts("小张",R.mipmap.run6,"聊天不是目的，能约出来才是重点"),
        contacts("吃货",R.mipmap.run7,"哪天带你去吃好吃的"),
        contacts("樱桃丸子",R.mipmap.run8,"公司旁边新开了一家奶茶店，哪天带你去尝尝"),
        contacts("励志师",R.mipmap.run9,"行动是成功的阶梯，行动越多，登得越高"),
        contacts("路人",R.mipmap.run10,"只做第一个我，不做第二个谁"),
        contacts("凹凸曼",R.mipmap.run11,"未来的路就在脚下"),
        contacts("光明使者",R.mipmap.run12,"光明创造瞎子"),
        contacts("唯❤",R.mipmap.run13,"燃烧的烈焰，温暖心房"),
        contacts("玖依",R.mipmap.run14,"仰望星空中"),
        contacts("落叶",R.mipmap.run15,"已有对象，勿搭讪！！"),
        contacts("尘埃",R.mipmap.run16,"随风而逝，落地成河"),
        contacts("烛光残影",R.mipmap.run17,"照亮人世间，万物"),
        contacts("裂开",R.mipmap.run18,"此刻再无文案。。")
    )

    override fun onBackPressed() {
       startActivity(Intent(this,MainActivity::class.java))
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_left_contact)

        val adapter=contactAdapter(this,R.layout.list_items,contacts)
        listView.adapter=adapter

        left_middle.setOnClickListener {
            startActivity(Intent(this,MiddleContact::class.java))
        }
        left_right.setOnClickListener {
            startActivity(Intent(this,RightContact::class.java))
        }
    }
}
data class contacts(val name:String,val img:Int,val content:String)
class contactAdapter(activity:Activity,val resourceId:Int,data:Array<contacts>):ArrayAdapter<contacts>(activity,resourceId,data)
{
    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view:View

        if (convertView==null){
            view=LayoutInflater.from(context).inflate(resourceId,parent,false)
        }else{
            view=convertView
        }
        val img:ImageView=view.findViewById(R.id.contactImg)
        val name:TextView=view.findViewById(R.id.contactName)
        val content:TextView=view.findViewById(R.id.contact_content)
        val contact=getItem(position)
        if (contact!=null){
            img.setImageResource(contact.img)
            name.text=contact.name
            content.text=contact.content
        }
        return view
    }
}